package com.hedl.classroom.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Big Watermelon
 * @description 自定义DaoAuthenticationProvider,并重写DaoAuthenticationProvider
 * @date 2023/12/09/11:21
 */
@Component
public class DaoAuthenticationProviderCustom extends DaoAuthenticationProvider {

    @Autowired
    @Override
    public void setUserDetailsService(UserDetailsService userDetailsService) {
        super.setUserDetailsService(userDetailsService);
    }


    /**
     * 重写校验密码的方法，因为我们统一认证的入口，有些认证不需要校验密码
     * @param userDetails
     * @param authentication
     * @throws AuthenticationException
     */
    @Override
    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
        //这里什么都不需要写，写了就不能得到令牌了，因为这个地方我们重写了密码验证；加上如下内容则会报错；
        //super.additionalAuthenticationChecks(userDetails,authentication);
    }
}
